﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;

public class TipTweenScript : MonoBehaviour 
{


    [SerializeField]
    private Text text;

    private Image image;

    private bool isPlay;

    private Color _color;

    private Color endColor = new Color(0f, 0f, 0f, 0.9f);

    public UnityEvent myEvent;

    private void Awake()
    {
        image = GetComponent<Image>();
    }

    private void OnEnable()
    {
        image.color = new Color(0f, 0f, 0f, 0f);
        _color = image.color;
        isPlay = true;
    }

    private void OnDisable()
    {
        image.color = new Color(0f, 0f, 0f, 0f);
        isPlay = false;
    }

    private void Update()
    {
        if (isPlay)
        {
            _color = Color.Lerp(_color, endColor, Time.deltaTime * 2f);
            image.color = _color;
            if (_color.a > endColor.a - 0.1f)
            {
                ShowTip();
                isPlay = false;
            }
        }
    }

    private void ShowTip()
    {

        transform.Find("Text").GetComponent<TypewriterEffect>().OnStart();
        transform.Find("Text").GetComponent<TypewriterEffect>().myEvent = myEvent;
    }


}
